package com.qiyi.player.wonder.plugins.share.view.parts
{
   import com.iqiyi.components.videoshare.EmbedCodesUI;
   import com.qiyi.player.wonder.common.ui.SimpleBtn;
   import com.qiyi.player.base.pub.EnumItem;
   import flash.events.MouseEvent;
   import flash.system.*;
   
   public class ShareEmbedCodes extends EmbedCodesUI
   {
      
      public function ShareEmbedCodes(param1:String, param2:Number, param3:Number, param4:Number, param5:String, param6:String, param7:String, param8:String, param9:String, param10:Boolean, param11:EnumItem) {
         super();
         this.initBtn();
         this._startTime = param3;
         this._endTime = param4;
         this._totalDuration = param2;
         this._pageURL = param1;
         this._flvTitle = param5;
         this._flvPic = param6;
         this._alumId = param7;
         this._tvid = param8;
         this._vid = param9;
         this._movieIsMember = param10;
         this._channel = param11;
         this.initListeners();
         this.updateShareTime(Math.ceil(param3 / 1000).toString(),Math.ceil((param4 == -1?this._totalDuration:param4) / 1000).toString());
         copyOK.visible = false;
         copyOK.mouseEnabled = false;
         copyOK.mouseChildren = false;
      }
      
      public static const playerURI:String = "http://player.video.qiyi.com/";
      
      private static const TEXT_COPY_FLASH:String = "复制flash地址";
      
      private static const TEXT_COPY_VIDEO:String = "复制视频地址";
      
      private static const TEXT_COPY_HTML:String = "复制Html地址";
      
      public static const ALIGN_V:int = 0;
      
      public static const ALIGN_H:int = 1;
      
      private var _copyFlashBtn:SimpleBtn;
      
      private var _copyVideoBtn:SimpleBtn;
      
      private var _copyHtmlBtn:SimpleBtn;
      
      private var _flvTitle:String;
      
      private var _pageURL:String;
      
      private var _totalDuration:Number;
      
      private var _flvPic:String;
      
      private var _alumId:String;
      
      private var _tvid:String;
      
      private var _vid:String;
      
      private var _videoURL:String = "";
      
      private var _flashURL:String = "";
      
      private var _htmlURL:String = "";
      
      private var _startTime:Number;
      
      private var _endTime:Number;
      
      private var _movieIsMember:Boolean;
      
      private var _channel:EnumItem;
      
      private var _shareURLTile:String;
      
      private function initBtn() : void {
         this._copyFlashBtn = new SimpleBtn(TEXT_COPY_FLASH,100);
         addChildAt(this._copyFlashBtn,0);
         this._copyVideoBtn = new SimpleBtn(TEXT_COPY_VIDEO,100);
         this._copyVideoBtn.y = 31;
         addChildAt(this._copyVideoBtn,0);
         this._copyHtmlBtn = new SimpleBtn(TEXT_COPY_HTML,100);
         this._copyHtmlBtn.y = 62;
         addChildAt(this._copyHtmlBtn,0);
      }
      
      private function initListeners() : void {
         this._copyFlashBtn.addEventListener(MouseEvent.CLICK,this.copyFlashURL,false,0,true);
         this._copyVideoBtn.addEventListener(MouseEvent.CLICK,this.copyVideoURL,false,0,true);
         this._copyHtmlBtn.addEventListener(MouseEvent.CLICK,this.copyHtmlURL,false,0,true);
      }
      
      private function destroyListener() : void {
         this._copyFlashBtn.removeEventListener(MouseEvent.CLICK,this.copyFlashURL,false);
         this._copyVideoBtn.removeEventListener(MouseEvent.CLICK,this.copyVideoURL,false);
         this._copyHtmlBtn.removeEventListener(MouseEvent.CLICK,this.copyHtmlURL,false);
      }
      
      private function copyFlashURL(param1:MouseEvent) : void {
         System.setClipboard(this.flashURL);
         this.playCopySuccess(this._copyFlashBtn.x + 32,this._copyFlashBtn.y + 20);
      }
      
      private function copyVideoURL(param1:MouseEvent) : void {
         var _loc2_:RegExp = new RegExp("%26","g");
         var _loc3_:String = this.videoURL.replace(_loc2_,"&");
         if(_loc3_ == this._pageURL + "?share_sTime=" + Math.ceil(this._startTime / 1000).toString() + "-share_eTime=" + Math.ceil((this._endTime == -1?this._totalDuration:this._endTime) / 1000).toString())
         {
            System.setClipboard(this._pageURL);
         }
         else
         {
            System.setClipboard(_loc3_);
         }
         this.playCopySuccess(this._copyVideoBtn.x + 32,this._copyVideoBtn.y + 20);
      }
      
      private function copyHtmlURL(param1:MouseEvent) : void {
         System.setClipboard(this.htmlURL);
         this.playCopySuccess(this._copyHtmlBtn.x + 32,this._copyHtmlBtn.y + 20);
      }
      
      private function playCopySuccess(param1:Number, param2:Number) : void {
         copyOK.x = param1;
         copyOK.y = param2;
         copyOK.visible = true;
         copyOK.gotoAndPlay(2);
      }
      
      public function setAlign(param1:int) : void {
         if(param1 == ALIGN_V)
         {
            this._copyFlashBtn.x = 0;
            this._copyFlashBtn.y = 0;
            this._copyVideoBtn.x = 0;
            this._copyVideoBtn.y = 31;
            this._copyHtmlBtn.x = 0;
            this._copyHtmlBtn.y = 62;
         }
         else if(param1 == ALIGN_H)
         {
            this._copyFlashBtn.x = 0;
            this._copyFlashBtn.y = 0;
            this._copyVideoBtn.x = 111;
            this._copyVideoBtn.y = 0;
            this._copyHtmlBtn.x = 222;
            this._copyHtmlBtn.y = 0;
         }
         
      }
      
      public function updateShareTime(param1:String, param2:String) : void {
         this._shareURLTile = "share_sTime=" + param1 + "-share_eTime=" + param2;
         this.setVideoURL(this._shareURLTile);
         this.setFlashURL(param1,param2);
         this.setHtmlCode();
         var _loc3_:VideoShareEvent = new VideoShareEvent(VideoShareEvent.Evt_EmbedCodeReady);
         _loc3_.flashURL = this.flashURL;
         _loc3_.videoURL = this.videoURL;
         dispatchEvent(_loc3_);
      }
      
      private function setVideoURL(param1:String) : void {
         var _loc2_:RegExp = null;
         if(this._pageURL != null)
         {
            this.videoURL = this._pageURL.indexOf("?") == -1?this._pageURL + "?" + param1:this._pageURL + "&" + param1;
            _loc2_ = new RegExp("&","g");
            this.videoURL = this.videoURL.replace(_loc2_,"%26");
         }
      }
      
      private function setFlashURL(param1:String, param2:String) : void {
         var _loc3_:String = null;
         if(this._pageURL.split("/")[2] == "yule.qiyi.com")
         {
            _loc3_ = playerURI + this._vid + "/" + param1 + "/" + param2 + "/" + this._pageURL.split("/")[2].split(".")[0] + "/" + this._pageURL.split("qiyi.com/")[1].split(".html")[0] + ".swf" + "-albumId=" + this._alumId + "-tvId=" + this._tvid + "-isPurchase=" + (this._movieIsMember?"1":"0") + "-cnId=" + this._channel.id;
         }
         else
         {
            _loc3_ = playerURI + this._vid + "/" + param1 + "/" + param2 + "/" + this._pageURL.split("qiyi.com/")[1].split(".html")[0] + ".swf" + "-albumId=" + this._alumId + "-tvId=" + this._tvid + "-isPurchase=" + (this._movieIsMember?"1":"0") + "-cnId=" + this._channel.id;
         }
         this.flashURL = _loc3_;
      }
      
      private function setHtmlCode() : void {
         this.htmlURL = "<embed src=\"" + this.flashURL + "\" quality=\"high\" width=\"480\" height=\"400\" align=\"middle\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\"></embed>";
      }
      
      public function get htmlURL() : String {
         return this._htmlURL;
      }
      
      public function set htmlURL(param1:String) : void {
         this._htmlURL = param1;
      }
      
      public function get flashURL() : String {
         return this._flashURL;
      }
      
      public function set flashURL(param1:String) : void {
         this._flashURL = param1;
      }
      
      public function get videoURL() : String {
         return this._videoURL;
      }
      
      public function set videoURL(param1:String) : void {
         this._videoURL = param1;
      }
      
      public function GC() : void {
         this.destroyListener();
      }
   }
}
